<template>
  <div>
    <wl-upload-oss-files
      v-model="imgPath"
      :maxNum="5"
      uploadType="hadoop"
      :uploadUrl="getUploadUrl"
      getSignUrl="/api/ac/setting/getHadoopService/getSign"
      fileName="origin"
      :beforeUploadFilter="uploadFilter"
      @result="ossFilesResultAction"
      :format="['jpg','jpeg','png']">
    </wl-upload-oss-files>
  </div>
</template>

<script>
export default {
  name: 'UploadImg',
  data () {
    return {
      modalShow: false,
      imgPath: '',
      loading: false,
      modalTitle: '',
      tableRow: {}
    }
  },
  props: {
    index: {
      type: Number,
      default: () => {
        return 0
      }
    },
    list: {
      type: Array,
      default: () => {
        return []
      }
    }
  },
  computed: {
    getUploadUrl () {
      return this.$config.upLoadFileUrl
    }
  },
  methods: {
    modelAction (path) {
      this.imgPath = path
    },
    okAction () {
      this.$emit('result', this.imgPath, this.index)
      this.modelAction()
    },
    uploadFilter (file, uploadList, filterReturn) {
      let isExit = false
      if (uploadList.length > 0) {
        uploadList.forEach(item => {
          if (item.url.indexOf(file.name) !== -1) {
            isExit = true
          }
        })
      }
      if (isExit) {
        this.errMsgAction(file.name, '【文件已经存在】')
        return { errcode: false, selfShow: true }
      }
      return { errcode: true }
    },
    ossFilesResultAction (val) {
      // console.log('图片处理结束', val)
    },
    errMsgAction (title, desc) {
      this.$Notice.warning({
        title: title,
        desc: desc,
        duration: 0
      })
    }
  }
}
</script>

<style scoped>

</style>
